//
//  MyViewController.m
//  QQ-Music
//
//  Created by lanou3g on 15/10/30.
//  Copyright © 2015年 lanou3g. All rights reserved.
//

#import "MyViewController.h"
#import "AppDelegate.h"
#import "LoginViewController.h"
#import "RegistViewController.h"
#import "localitySongsViewController.h"
#import "songsViewController.h"
#import "dewnloadViewController.h"
#import "DownMVViewController.h"

@interface MyViewController ()<UIImagePickerControllerDelegate,UITableViewDataSource,UITableViewDelegate>

@property (strong, nonatomic) IBOutlet UIButton *loginButton;

@property (strong, nonatomic) IBOutlet UIButton *imageButton;

@property (weak, nonatomic) IBOutlet UITableView *mySongListTableView;

@end

@implementation MyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"我的";
    self.view.backgroundColor = [[UIColor alloc] initWithRed:254.0/255 green:200.0/255 blue:249.0/255 alpha:1.0];
    
    self.mySongListTableView.delegate = self;
    self.mySongListTableView.dataSource = self;

    UIButton *menuBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    menuBtn.frame = CGRectMake(0, 0, 20, 18);
    [menuBtn setBackgroundImage:[UIImage imageNamed:@"11.png"] forState:UIControlStateNormal];
    [menuBtn addTarget:self action:@selector(openOrCloseLeftList) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:menuBtn];
    self.navigationController.navigationBar.translucent = NO;
    

}
#pragma mark - Button点击事件
- (void) openOrCloseLeftList
{
    AppDelegate *tempAppDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    
    if (tempAppDelegate.LeftSlideVC.closed)
    {
        [tempAppDelegate.LeftSlideVC openLeftView];
    }
    else
    {
        [tempAppDelegate.LeftSlideVC closeLeftView];
    }
}

#pragma mark - 登录button点击事件
- (IBAction)loginButtonAction:(id)sender {
    LoginViewController *loginVC = [[LoginViewController alloc] init];
    [self.navigationController pushViewController:loginVC animated:YES];
    
}

//#pragma mark - 注册button点击事件
//- (IBAction)registButtonAction:(id)sender {
//    RegistViewController *registVC = [[RegistViewController alloc] init];
//    [self.navigationController pushViewController:registVC animated:YES];
//}

#pragma mark - 上传头像button点击事件
- (IBAction)imageButtonAction:(id)sender {
    LoginViewController * loginVC = [[LoginViewController alloc] init];
    if ([self.loginButton.titleLabel.text isEqualToString:@"登录/注册"]) {
        [self.navigationController pushViewController:loginVC animated:YES];
    }else{
    
    //弹框
    UIAlertController *actionsheet = [UIAlertController alertControllerWithTitle:@"智能提示" message:@"请选择相机或者相册" preferredStyle:UIAlertControllerStyleActionSheet];
    //事件
    UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"相册" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
        //imagePicker.delegate = self;
        [self.navigationController presentViewController:imagePicker animated:YES completion:nil];
        
        
    }];
    
    UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"相机" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        if (UIImagePickerControllerSourceTypeCamera) {
            
            UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
            imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
            [self.navigationController presentViewController:imagePicker animated:YES completion:nil];
        } else {
            TRLog(@"傻了吧~~这是模拟器啊! !");
        }
       
        
    }];
    UIAlertAction *action3 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:nil];
    [actionsheet addAction:action1];
    [actionsheet addAction:action2];
    [actionsheet addAction:action3];
    [self.navigationController presentViewController:actionsheet animated:YES completion:nil];
  
    }
}
#pragma mark - 代理方法
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{
    
    UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake(145, 117, 85, 114)];
    [self.imageButton addSubview:imageV];
    
}

#pragma mark - 本地歌曲点击事件
//本地歌曲
- (IBAction)localitySongsButton:(id)sender {
    localitySongsViewController *localVC = [localitySongsViewController new];
    [self.navigationController pushViewController:localVC animated:YES];
}
//下载歌曲
- (IBAction)downloadSongsButton:(id)sender {
    dewnloadViewController *downVC = [dewnloadViewController new];
    [self.navigationController pushViewController:downVC animated:YES];
    
}
//最近播放
- (IBAction)recentlyPlayButton:(id)sender {
}
//我的最爱
- (IBAction)myFavoriteButton:(id)sender {
}
//下载mv
- (IBAction)downloadMVButton:(id)sender {
    DownMVViewController *downMV = [DownMVViewController new];
    [self.navigationController pushViewController:downMV animated:YES];
}
//听歌识曲
- (IBAction)recognitionSongsButton:(id)sender {
}

#pragma mark - TableViewDelegate

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell * cell = [[UITableViewCell alloc] init];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self.mySongListTableView deselectRowAtIndexPath:indexPath animated:YES];
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 50;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    
    UIView * headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.mySongListTableView.frame.size.width, 50)];
    UILabel * myListLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, headerView.frame.origin.y, 100, headerView.frame.size.height)];
    myListLabel.text = @"我的歌单";
    [headerView addSubview:myListLabel];
    UILabel * numLabel = [[UILabel alloc] initWithFrame:CGRectMake(([UIScreen mainScreen].bounds.size.width)-55, headerView.frame.origin.y, 10, headerView.frame.size.height)];
    numLabel.textColor = [UIColor pinkColor];
    numLabel.text = @"3";
    [headerView addSubview:numLabel];
    UIButton * button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.frame = CGRectMake(([UIScreen mainScreen].bounds.size.width)-40, 12.5, 25, 25);
    UIImage * image = [UIImage imageNamed:@"iconfont-qianjinjiantou.png"];
    image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [button setImage:image forState:UIControlStateNormal];
    [headerView addSubview:button];
    return headerView;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 50;
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView * footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.mySongListTableView.frame.size.width, 60)];
    UIButton * button = [[UIButton alloc] initWithFrame:CGRectMake(15, 12.5, 25, 25)];
    UIImage * image = [UIImage imageNamed:@"iconfont-jiahao.png"];
    image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [button setImage:image forState:UIControlStateNormal];
//    button.backgroundColor = [[UIColor alloc] initWithRed:254.0/255 green:190.0/255 blue:249.0/255 alpha:1.0];
    [footerView addSubview:button];
    UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(55, -5, 100, footerView.frame.size.height)];
    label.text = @"新建歌单";
    [footerView addSubview:label];
    return footerView;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
